package pro.softzhang.algo.lc100;

import pro.softzhang.algo.common.TreeNode;
import pro.softzhang.algo.flag.knowledge.KBinaryTree;
import pro.softzhang.algo.flag.x.XOptimal;

@KBinaryTree
public class LC114_FlattenBinaryTreeToLinkedList {
    public static void main(String[] args) {

    }

    /**
     * 最优解
     */
    @XOptimal
    static
    class Solution {
        TreeNode last = null;
        public void flatten(TreeNode root) {
            if (root == null) return;
            flatten(root.right);
            flatten(root.left);

            root.right = last;
            root.left = null;
            last = root;
        }
    }
}
